
package cn.com.shiro.filter;

import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authz.AuthorizationFilter;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
/**
 * @className 
 * @descripion 
 * @author WangJun
 * @date 2018年7月2日上午9:15:20
 */
public class RolesOr extends AuthorizationFilter {

	@Override
	protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue)
			throws Exception {
		// TODO Auto-generated method stub
		Subject subject = getSubject(request, response);
		String[] roles = (String[]) mappedValue;
		if(roles==null || roles.length==0) {
			return true;
		}
		for(String role:roles) {
			if(subject.hasRole(role)) {
				return true;
			}
		}
		return false;
	}
	
}
